import com.yuanye.beans.*;
import com.yuanye.beans.Component.BeanLife;
import com.yuanye.beans.controller.ArtController;
import com.yuanye.beans.controller.StudentControllerB;
import com.yuanye.beans.controller.StuedntControllerA;
import com.yuanye.model.Student;
import com.yuanye.model.UserInfo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Kiteye
 * @date 2023/7/8
 * @Description
 */

public class App {
    public static void main(String[] args) {
//        ApplicationContext applicationContext =
//                new ClassPathXmlApplicationContext("spring-config.xml");
//        UserController userController = applicationContext.getBean("userController", UserController.class);
//        userController.sayHi();
//
//        UserService userService = applicationContext.getBean("userService",UserService.class);
//        userService.sayhi();
//
//        UserRepository userRepository = applicationContext.getBean("userRepository",UserRepository.class);
//        userRepository.sayhi();
//
//        UserComponent userComponent = applicationContext.getBean("userComponent",UserComponent.class);
//        userComponent.sayHi();
//
//        UserConfiguration userConfiguration = applicationContext.getBean("userConfiguration",UserConfiguration.class);
//        userConfiguration.sayHi();

//        UserInfo userInfo = applicationContext.getBean("UserFo",UserInfo.class);
//        System.out.println(userInfo);

//        // 这里只是校验，因为没有tomcat
//        ArtController artController = applicationContext.getBean("artController",ArtController.class);
//        artController.addArt("这里是注解获取方法","目前Service注解被注入在了Controller注解里面");

//        StuedntControllerA stuedntControllerA = applicationContext.getBean("stuedntControllerA", StuedntControllerA.class);
//        Student studentA = stuedntControllerA.getStudent();
//        System.out.println("ControllerA :" + studentA);
//        System.out.println("----------------------------------------");
//        StudentControllerB studentControllerB = applicationContext.getBean("studentControllerB", StudentControllerB.class);
//        Student studentB = studentControllerB.getStudent();
//        System.out.println("ControllerB:" + studentB);

        // 是ApplicationContext的子类，获得 spring 上下文对象
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
        BeanLife beanLife = context.getBean("beanLife",BeanLife.class);
        System.out.println("使用 Bean");
        System.out.println("销毁 Bean");
        context.destroy();

    }
}
